/*
** asm.h for  in /home/vanet_c//proj-kw/asm
** 
** Made by charles-edouard vanet
** Login   <vanet_c@epitech.net>
** 
** Started on  Thu Dec  6 12:26:00 2012 charles-edouard vanet
** Last update Sun Dec 16 14:50:16 2012 
*/

#ifndef		__ASM_H__
# define	__ASM_H__

# include	<stdlib.h>
# include	<unistd.h>
# include	<sys/types.h>
# include	<sys/stat.h>
# include	<fcntl.h>
# include	"my.h"
# include	"op.h"
# include	"korasm.h"

# define	REG		'r'
# define	DIRECT		'%'
# define	VIRG		','
# define	ERR_REG		2
# define	DIRECT_MAX	50

typedef struct	s_my_file
{
  struct s_my_file	*next;
  char			*instruction;
  int			line_nb;
  char			**tab_instruction;
}			t_my_file;

typedef struct	s_list
{
  struct s_list	*next;
  char		*name;
  t_my_file	*file;
  char		**tmp_for_label;
}		t_list;

typedef struct		s_label
{
  struct s_label	*next;
  char			*name;
  int			position;
}			t_label;

/*
**	main.c
*/
int	make_read(char *file, t_list **file_list, int nbr_files, int index);
int	get_my_ac(char **av);
/*
**	my_list.c
*/
int	my_put_in_list(t_list **list, char *str);
void	my_free_one_tlist(t_list *list);
t_list	*my_param_in_list(int ac, char **av);
void	my_free_list(t_list *list);

/*
**	check_param.c
**		chk_label : check le nombre de parametre dans la ligne et les mauvais chars
**		check_file : check si le fichier existe et s'il finit par .s
**		check_name : check si le premier parametre est ok et appelle check_nb_param
**		check_nb_param : vérifie si le nombre de parametres est correct
*/
int	check_file(char *file);
void	check_instruction(char *file, t_list **file_list, int nbr_files, int fd);
int	check_name(char *instruction);
char	*get_line_name(char *instruction);
int	check_nb_param(char *str, int nb_param);
/*
**	processing.c
*/
void	init_compilateur(t_list **file_list);
int	processing(char *instruction, int line_nb, t_list **file_list);
void	compilateur(t_list **file_list);
void	my_free_file_list(t_my_file **list);
int	reverse_list(t_my_file **reverse, char *instruction, int line_nb);
/*
**	my_errors.c
*/
void	aff_char_error(t_my_file **my_file, char *error);
void	check_instru_msg(t_list **list, int line, int type);
void	syntax_msg(t_list **list, t_my_file **my_file, char *error);
/*
**	init.c
*/
char	**init_tab(char **tab);
char	*fill_name_tab(char *result, char *str, int len);
/*
**	compilateur.c
*/
void	create_header(int *output, char *name, char *comment);
void	parsing_inst(int *output, char *str);
void	octet_codage(int *output, char *str);
void    instr_parameters(char *str, t_label **label, int *output);
/*
**	label.c
*/
void    put_in_label_list(t_label **label, char *str, int *buff);
void    is_label(t_label **label, char *str, int *buff);
void	write_label(t_label **label, char *str, int i, int *output);
/*
**	write.c
*/
void    my_be_write(int *output, int nb, int size);
void    write_reg(int *output, char *str, int i);
void    write_indirect(int *output, char *str, int i);
void    write_direct(int *output, char *str, int i);
void    write_file(int *buff, char *path);
/*
**	check_syntax_line.c
*/
int	check_syntax_line(t_list **file_list);
/*
**	folder_syntax/syntax_error.c
*/
int	syntax_error(t_list **list, t_my_file **my_file);
int	check_order_end_ok(char **name, int is_error,
			   t_list **list, t_my_file **my_file);
int	check_command(char *str, t_list **list, t_my_file **my_file);
int	check_order(t_list **list, t_my_file **my_file);
int	verif_result(t_list **list, char c, char *str, t_my_file **my_file);
/*
**	folder_syntax/indirection_too_far.c
*/
void	indirection_too_far_error(t_list **file_list, t_my_file **file);
int	my_str_is_num(char *str);
int	indirection_too_far(t_list **list, t_my_file **my_file);
/*
**	folder_syntax/label_undefine.c
*/
int	label_undefine(t_list **list, t_my_file **my_file);
/*
**	folder_syntax/register_error_label_syntax.c
*/
int	label_syntax(t_list **list, t_my_file **my_file);
void	register_msg(t_list **list, t_my_file **my_file, char *error);
/*
**	folder_syntax/direct_too_big.c
*/
int	direct_too_big(t_list **list, t_my_file **my_file);
void	direct_msg(t_list **list, t_my_file **my_file);
/*
**	folder_syntax/header_error.c
*/
void	header_msg(t_list **list, t_my_file **my_file, int type);
/*
**	folder_syntax/synt_func/
*/
int	synt_add(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_aff(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_and(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_fork(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_ld(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_ldi(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_lfork(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_live(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_lld(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_lldi(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_or(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_xor(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_st(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_sti(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_sub(char **tab, t_list **list, t_my_file **my_file, char **name);
int	synt_zjmp(char **tab, t_list **list, t_my_file **my_file, char **name);

# endif
